package com.lzy.cloud.permission.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.permission.dtos.RoleDto;
import com.lzy.cloud.permission.entity.Role;
import com.lzy.cloud.permission.mapper.RoleMapperExt;
import com.lzy.cloud.permission.service.RoleService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WIN7 on 2018/5/16.
 */
@Service
public class RoleServiceImpl implements RoleService{

    @Autowired
    RoleMapperExt roleMapperExt;

    @Override
    public Boolean delete(Long id) {
        return roleMapperExt.deleteByPrimaryKey(id)>0;
    }

    @Override
    public Boolean insertSelective(RoleDto roleDto) {
        return roleMapperExt.insertSelective(DozerUtils.map(roleDto, Role.class))>0;
    }

    @Override
    public Boolean update(RoleDto roleDto) {
        return roleMapperExt.updateByPrimaryKeySelective(DozerUtils.map(roleDto,Role.class))>0;
    }

    @Override
    public RoleDto selectById(Long id) {
        return DozerUtils.map(roleMapperExt.selectByPrimaryKey(id),RoleDto.class);
    }

    @Override
    public PageInfo<RoleDto> selectRole(Pager pager, RoleDto roleDto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<RoleDto> roleList = roleMapperExt.selectList(roleDto);
        return new PageInfo<RoleDto>(roleList);
    }

    @Override
    public List<RoleDto> selectAllRole(RoleDto roleDto) {
        return roleMapperExt.selectList(roleDto);
    }
}
